package com.atguigu.gulimall.order.web;

import com.atguigu.gulimall.order.entity.OrderEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.UUID;

@Controller
public class WebController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/{name}.html")
    public String name(@PathVariable("name") String name){
        return name;
    }

    @ResponseBody
    @GetMapping("/test/queue")
    public String testQueue(){
        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setOrderSn(UUID.randomUUID().toString());
        //给队列发消息,指定routing key
        //convertAndSend(String exchange, String routingKey, Object object)
        rabbitTemplate.convertAndSend("order-event-exchange","order.create.order",orderEntity);
        return "给mq发消息完成";
    }

}
